<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Bid_entity{
	var $id = 0;
	var $account_code = "";
	var $show_ref_no = "";
	var $offer_price = "";
	var $artist_production1 = "";
	var $artist_production2 = "";
	var $artist_production3 = "";
	var $artist_production4 = "";
	var $year1 = "";
	var $year2 = "";
	var $year3 = "";
	var $year4 = "";
	var $capacity1 = "";
	var $capacity2 = "";
	var $capacity3 = "";
	var $capacity4 = "";
	var $venue1 = "";
	var $venue2 = "";
	var $venue3 = "";
	var $venue4 = "";
	var $date_bid = "";
	
	function __destruct() {}
	function __construct() {}
    
	function is_set($account_code, $show_ref_no){
		$ci=& get_instance();
		
		$result = $ci->db->where( array('account_code'=>$account_code, 'show_ref_no'=>$show_ref_no ) )->get(TBL_BID)->result();
		if(!empty($result)){
			return clone_($this->init('id', $result[0]->id));
		}else{
			return false;
		}
	}
	
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_BID)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->account_code = $result[0]->account_code;
			$this->show_ref_no = $result[0]->show_ref_no;
			$this->offer_price = $result[0]->offer_price;
			$this->artist_production1 = $result[0]->artist_production1;
			$this->artist_production2 = $result[0]->artist_production2;
			$this->artist_production3 = $result[0]->artist_production3;
			$this->artist_production4 = $result[0]->artist_production4;
			$this->year1 = $result[0]->year1;
			$this->year2 = $result[0]->year2;
			$this->year3 = $result[0]->year3;
			$this->year4 = $result[0]->year4;
			$this->capacity1 = $result[0]->capacity1;
			$this->capacity2 = $result[0]->capacity2;
			$this->capacity3 = $result[0]->capacity3;
			$this->capacity4 = $result[0]->capacity4;
			$this->venue1 = $result[0]->venue1;
			$this->venue2 = $result[0]->venue2;
			$this->venue3 = $result[0]->venue3;
			$this->venue4 = $result[0]->venue4;
			$this->date_bid = $result[0]->date_bid;
			
			return $this;
		}
		return false;
	}
	
	function setAccountCode($input){ $this->account_code=$input; }
	function setShowRefNo($input){ $this->show_ref_no=$input; }
	function setOfferPrice($input){ $this->offer_price=$input; }
	function setArtistProduction1($input){ $this->artist_production1=$input; }
	function setArtistProduction2($input){ $this->artist_production2=$input; }
	function setArtistProduction3($input){ $this->artist_production3=$input; }
	function setArtistProduction4($input){ $this->artist_production4=$input; }	
	function setYear1($input){ $this->year1=$input; }
	function setYear2($input){ $this->year2=$input; }
	function setYear3($input){ $this->year3=$input; }
	function setYear4($input){ $this->year4=$input; }	
	function setCapacity1($input){ $this->capacity1 = $input; }
	function setCapacity2($input){ $this->capacity2 = $input; }
	function setCapacity3($input){ $this->capacity3 = $input; }
	function setCapacity4($input){ $this->capacity4 = $input; }	
	function setVenue1($input){ $this->venue1=$input; }
	function setVenue2($input){ $this->venue2=$input; }
	function setVenue3($input){ $this->venue3=$input; }
	function setVenue4($input){ $this->venue4=$input; }
	function setDateBid($input){ $this->date_bid=$input; }
		
	function getId(){ return $this->id; }
	function getAccountCode(){ return $this->account_code; }
	function getShowRefNo(){ return $this->show_ref_no; }
	function getOfferPrice() { return $this->offer_price;}
	function getArtistProduction1() { return $this->artist_production1;}
	function getArtistProduction2() { return $this->artist_production2;}
	function getArtistProduction3() { return $this->artist_production3;}
	function getArtistProduction4() { return $this->artist_production4;}	
	function getYear1(){ return $this->year1;}
	function getYear2(){ return $this->year2;}
	function getYear3(){ return $this->year3;}
	function getYear4(){ return $this->year4;}
	function getCapacity1(){ return $this->capacity1;}
	function getCapacity2(){ return $this->capacity2;}
	function getCapacity3(){ return $this->capacity3;}
	function getCapacity4(){ return $this->capacity4;}
	function getVenue1(){ return $this->venue1; }
	function getVenue2(){ return $this->venue2; }
	function getVenue3(){ return $this->venue3; }
	function getVenue4(){ return $this->venue4; }
	function getDateBid(){ return $this->date_bid; }
	
	function update()
	{
		$ci=& get_instance();
	
		$ci->db->set('account_code', $this->account_code);
		$ci->db->set('show_ref_no', $this->show_ref_no);
		$ci->db->set('offer_price', $this->offer_price);
		$ci->db->set('artist_production1', $this->artist_production1);
		$ci->db->set('artist_production2', $this->artist_production2);
		$ci->db->set('artist_production3', $this->artist_production3);
		$ci->db->set('artist_production4', $this->artist_production4);
		$ci->db->set('year1', $this->year1);
		$ci->db->set('year2', $this->year2);
		$ci->db->set('year3', $this->year3);
		$ci->db->set('year4', $this->year4);
		$ci->db->set('capacity1', $this->capacity1);
		$ci->db->set('capacity2', $this->capacity2);
		$ci->db->set('capacity3', $this->capacity3);
		$ci->db->set('capacity4', $this->capacity4);
		$ci->db->set('venue1', $this->venue1);
		$ci->db->set('venue2', $this->venue2);
		$ci->db->set('venue3', $this->venue3);
		$ci->db->set('venue4', $this->venue4);
		$ci->db->set('date_bid', $this->date_bid);
		
		$ci->db->where('id', $this->id)->update(TBL_BID);
	}
	
	function createNewBidEntity($account_code, $show_ref_no){
		$ci=& get_instance();
		
		$ci->db->set('account_code', $account_code);
		$ci->db->set('show_ref_no', $show_ref_no);
		
		$ci->db->insert(TBL_BID);
		
		return $ci->db->insert_id();
	}
	
	function getOfferPriceWonBid($show_ref, $bidderCode){
		$ci=& get_instance();
		$record = $ci->db->where(array('show_ref_no'=>$show_ref, 'account_code'=>$bidderCode))->get(TBL_BID)->result();
		return $record[0]->offer_price;
	}
	
	function getMyBid($bidderCode){
		$ci=& get_instance();
		return $ci->db->where('account_code',$bidderCode)->get(TBL_BID)->result();
	}
	
	function getTotalNumberBids($show_ref){
		$ci=& get_instance();
		$records = $ci->db->where('show_ref_no',$show_ref)->get(TBL_BID)->result();
		return count($records);
	}
	
}
